package com.p2p.common.base;

import java.sql.Timestamp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.p2p.common.interceptor.databind.DataBind;
import com.p2p.common.interceptor.databind.DataBindManager;
import com.p2p.common.interceptor.databind.DataBindType;
import com.p2p.user.po.User;
import com.p2p.user.po.UserRole;
import com.p2p.user.service.UserRoleService;
import com.p2p.user.service.UserService;

/**
 * Created by Allen on 2017/3/17.
 */
public abstract class BaseController {
    protected static final Logger logger = LoggerFactory.getLogger(BaseController.class);
    private static final DataBind<Long> USER_ID_BIND = DataBindManager.getInstance().getDataBind(DataBindType.USER_ID);

    @Autowired
    private UserService userService;

    @Autowired
    private UserRoleService userRoleService;

    //获取用户ID
    public Long getUserId() {
        return USER_ID_BIND.get();
    }

    
    
    public Long getRoleId() {
    	System.out.println("进入");
        UserRole userRole = userRoleService.selectOne(new EntityWrapper<UserRole>().eq("user_id", getUserId()));
        System.out.println("userid"+userRole.getId());
        System.out.println("id="+userRole.getUserId());
        return userRole.getRoleId();
    }

    /**
     * 获取当前时间戳
     *
     * @return
     */
    public Long getCurrentTimeMillis() {
        return System.currentTimeMillis();
    }

    /**
     * 获取当前时间戳
     *
     * @return
     */
    public Timestamp getCurrentTimeTimestamp() {
        return new Timestamp(System.currentTimeMillis());
    }
}